Component({
  mixins: [],
  data: {
    mapData: [],
    numberCount: {},//数据统计
    newVideo: [],
    newSalesList: [],
    newApplyLikeList: [],
    modalVd: false,
    vdUrl: '', //预览视频
    picUrl: '',
  },
  props: {},
  didMount() {
    // var app = getApp();
    // app.getUser();
    var that = this;
    my.authorize({
      scopes: 'scope.userInfo',
      success: (res) => {
        my.getAuthUserInfo({
          success: (userInfo) => {
            that.numberCount();
            that.newApplyList();
            that.partiTrend();
            that.newSalesList();
            that.newApplyLikeList();
            // my.alert({
            //   content: 'user' + JSON.stringify(userInfo),
            // });
          }
        });
      },
    });
    
    // my.getStorage({
    //   key: 'users',
    //   success: function (res) {
    //     console.log(res)
    //     if(res.data.user_name) {
    //       that.numberCount();
    //       that.newApplyList();
    //       that.partiTrend();
    //       that.newSalesList();
    //       that.newApplyLikeList();
    //     }
    //   },
    //   fail: function (res) {
    //     that.getAuth();
    //     my.alert({ content: res.errorMessage });
    //   }
    // });

  },
  didUpdate() { },
  didUnmount() {

  },
  methods: {
    // imgClick(){
    //   var app = getApp();
    //   var url = app.upimg();
    //   this.setData({
    //     picUrl:url
    //   })
    // },
    upvideo() {
      my.qn.chooseFile({
        count: 1,   // 返回的文件数，默认 1
        type: 0x04, // 图片=0x01，文档=0x02，多媒体=0x04，自由组合，默认 0x01
        success: (res) => {
          //my.alert({ title: res.apFilePaths[0] });
          const { cloud } = getApp();
          my.showLoading({ content: '上传中...' });
          var result = cloud.file.uploadFile({
            filePath: res.apFilePaths[0],
            fileType: 'video',
          });
          result.then(function (data) {
            // 提交到后端处理
            my.hideLoading();
            my.alert({ title: JSON.stringify(data) });
          });
          //console.log(res); // {"apFilePaths":["https://appres.wiflill.com/publictmp/2737175a-6c44-4ed4-ba84-6675e7e258d9test1.xlsx","https://appres.wiflill.com/publictmp/40d43fa5-1de6-4bce-a287-4471a5a47f97test2.xlsx"],"success":true} 
        },
      });
    },
    //关闭视频模态框
    closeVideo(e) {
      var name = e.currentTarget.dataset.name;
      this.setData({
        [name]: false,
        vdUrl: '',
      });
    },
    /**
     * 实例化消费者小程序
     */
    tplInstantiate() {
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.instantiate";
      var params = { 'clients': 'taobao', 'name': '蛋小强红人', 'template_id': '3000000002156421', ext_json: { "sellerNick": "浪子arvin", "user_id": '15' }, 'template_version': '0.0.4', 'appkey': '28272010', 'description': '店铺红人-短视频信息流为店铺提流', 'icon': 'https://ossgw.alicdn.com/taobao-miniapp/img/7eb7be64801658c35bce1df108465c5f.png' };
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 更新C端小程序
     */
    tplUpdate() {
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.updateapp";
      var params = { 'clients': 'taobao', 'id': '3000000003068463', 'template_id': '3000000002156421', 'template_version': '0.0.4', ext_json: { "sellerNick": "浪子arvin", "user_id": '15' } };
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 上线C端小程序
     */
    tplOnlineapp() {
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.onlineapp";
      var params = { 'clients': 'taobao', 'app_id': '3000000003068463', 'template_id': '3000000002156421', 'template_version': '0.0.4','app_version':'0.0.1'};
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    /**
     * 查询C端小程序
     */
    tplQueryapp(){
      var app = getApp();
      var that = this;
      var apiurl = "taobao.miniapp.template.queryapp";
      var params = { 'page_size': '20', 'page_num': '1', 'template_id': '3000000002156421'};
      app.xdapiTop(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    instantiate1() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsMiniApp.Instantiate";
      var params = { 'clients': 'taobao', 'name': '店铺红人', 'template_id': '3000000002156421', 'template_version': '0.0.4', 'appkey': '28272010', 'description': '店铺红人-短视频信息流为店铺提流', 'icon': 'https://ossgw.alicdn.com/taobao-miniapp/img/7eb7be64801658c35bce1df108465c5f.png' };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        my.alert({ title: JSON.stringify(res) });
      });
    },
    //预览视频
    openVideo(e) {
      var src = e.currentTarget.dataset.src;
      this.setData({
        vdUrl: src,
        modalVd: true,
      });
    },
    httpPost() {
      this.httptest();
      return true;
    },
    //最新上传的视频
    newApplyList() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsIndex.NewApplyList";
      var params = { 'pagesize': 10, page: 1 };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        that.setData({
          newVideo: res.list
        })
      });
    },
    //最受欢迎的视频
    newApplyLikeList() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsIndex.NewApplyLikeList";
      var params = { 'pagesize': 10, page: 1 };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        console.log(res);
        that.setData({
          newApplyLikeList: res.list
        })
        console.log(666666);
        console.log(that.data.newApplyLikeList);
      });
    },
    //统计
    numberCount() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsIndex.NumberCount";
      var params = {};
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        that.setData({
          numberCount: res
        })
      });
    },
    //近7天数据
    partiTrend() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsIndex.ParticipateTrendList";
      var params = { 'difference_time': '7' };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        that.setData({
          mapData: res.list
        })
      });
    },
    //近期活动列表
    newSalesList() {
      var app = getApp();
      var that = this;
      var apiurl = "App.ShopRedsIndex.NewSalesList";
      var params = { 'pagesize': 5, page: 1 };
      app.xdapis(apiurl, params, function (res) {
        my.hideLoading();
        that.setData({
          newSalesList: res.list
        })
      });
    },
    httptest() {
      var app = getApp();
      var apiurl = "App.ShopRedsInfos.GetUserOnsale";
      var params = { "pagesize": "4", "name": "1" };
      app.xdapis(apiurl, params, function (e) {
        my.hideLoading();
        my.alert({
          content: '成功: ' + JSON.stringify(e)
        });
      });
    },
    auth() {
      my.authorize({
        scopes: 'scope.userInfo',
        success: (res) => {
          my.getAuthUserInfo({
            success: (userInfo) => {
              my.alert({
                content: 'user' + JSON.stringify(userInfo),
              });
            }
          });
        },
      });
    },
    clea() {
      my.qn.cleanToken({
        success: (res) => {
          my.alert({
            title: '成功1',
          });
        },
        fail: (res) => {
          my.alert({
            title: '失败!',
          });
        }
      })
    },
    tiyan() {
      my.alert({
        title: '亲',
        content: '您本月的账单已出',
        buttonText: '我知道了',
        success: () => {
          my.alert({
            title: '用户点击了「我知道了」',
          });
        }
      });
    },
    yulan() {
      my.alert({
        title: '亲',
        content: '您本月的账单已出',
        buttonText: '我知道了',
        success: () => {
          my.alert({
            title: '用户点击了「我知道了」',
          });
        }
      });
    },

  }
});
